﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConfigCreate.Attributes
{
    /// <summary>
    /// 控件特性基类
    /// </summary>
    public class CreateBaseAttribute : Attribute
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="header_name">大类别名</param>
        /// <param name="group_name">组名</param>
        /// <param name="title">控件标题</param>
        /// <exception cref="ConfigException">任意参数为空时报错</exception>
        public CreateBaseAttribute(string header_name, string group_name, string title)
        {
            //if (string.IsNullOrWhiteSpace(header_name))
            //    throw new ConfigException("大类别标题不能为空");
            //if (string.IsNullOrWhiteSpace(group_name))
            //    throw new ConfigException("组名不能为空");
            if (CheckTitle && string.IsNullOrWhiteSpace(title))
                throw new ConfigException("控件标题不能为空");
            HeaderName = header_name;
            GroupName = group_name;
            Title = title;
        }

        /// <summary>
        /// 大类别标题
        /// </summary>
        public string HeaderName { get; set; }
        /// <summary>
        /// 组名
        /// </summary>
        public string GroupName { get; set; }
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; } = string.Empty;
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; } = string.Empty;
        /// <summary>
        /// 加星号，必须项
        /// </summary>
        public bool Necessary { get; set; }
        /// <summary>
        /// 大类别排序索引
        /// </summary>
        public int HeaderIndex { get; set; } = -1;
        /// <summary>
        /// 组排序索引
        /// </summary>
        public int GroupIndex { get; set; } = -1;
        /// <summary>
        /// 是否检查标题
        /// </summary>
        protected virtual bool CheckTitle { get; set; } = true;
       
        internal int? GetHeaderIndex
        {
            get
            {
                if (HeaderIndex < 0)
                    return null;
                return HeaderIndex;
            }
        }
        
        internal int? GetGroupIndex
        {
            get
            {
                if (GroupIndex < 0)
                    return null;
                return GroupIndex;
            }
        }

        
    }
}
